<?php

namespace app\admin\controller;

/**
 * Created by PhpStorm.
 * User: strong
 * Date: 2018/4/3
 * Time: 15:54
 */

use think\Request;
use think\Db;
use app\admin\controller\Base;
use think\Session;


class Index extends Base
{
    public function index()
    {
        $this->isLogin();
        return view();
    }

    public function checkAjax()
    {
        $this->isLogin();
        $db = Db::name('set');
        $id = $_POST['id'];

        if (Request::instance()->isAjax()) {
            if ($id == '1') {
                $this->upd(1);
                $i = $db->where('id', 1)->find();
                if ($i['switch'] == 1) {
                    echo 1;
                }
            } else {
                $this->upd(0);
                $i = $db->where('id', 1)->find();
                if ($i['switch'] == 0) {
                    echo 2;
                }
            }
        }
    }

    public function upd($i)
    {
        $db = Db::name('set');
        $res = $db->where('id', 1)->update([
            'switch' => $i
        ]);
    }

    public function activity()
    {
        $this->isLogin();
        return view();
    }

    public function ajaxnum($id)
    {
        $this->isLogin();
        if (Request::instance()->isAjax()) {
            $db = Db::name('admin_chars');
            $res = $db->where('chars', $id)->update([
                'stat' => 2
            ]);
        }

    }

    public function ajaxnumno($id)
    {
        $this->isLogin();
        if (Request::instance()->isAjax()) {
            $db = Db::name('admin_chars');
            $res = $db->where('chars', $id)->update([
                'stat' => 1
            ]);
        }
    }
}